//SWEP.Base = ""

SWEP.Author = "Night-Eagle"
SWEP.Contact = "gmail sedhdi"
SWEP.PrintName = ""
SWEP.Slot = 0
SWEP.SlotPos = 0
SWEP.ViewModelFlip = false

SWEP.Spawnable = false
SWEP.AdminSpawnable = false

SWEP.ViewModel = "models/weapons/v_bugbait.mdl"
SWEP.WorldModel = "models/weapons/w_bugbait.mdl"
SWEP.HoldType = "normal"

if (SERVER) then
	AddCSLuaFile("shared.lua")
end

function SWEP:Initialize()
	if SERVER then
		self:SetWeaponHoldType(self.HoldType)
	end
end

function SWEP:Think()
	local GM = gmod.GetGamemode()
	if SERVER then
		local uid = self.Owner:UniqueID()
		local inv = GM.pldat[uid].inventory
		itemclass = GM.pldat[uid].invsel
	elseif CLIENT then
		itemclass = GM.invsel.curclass
	end
	
	if itemclass then
		local item = GM.items[itemclass]
		if item then
			if item.onThink then
				local b,err = pcall(item.onThink,item,self.Owner)
				if not b then
					Error("\n",err)
				end
			end
		end
	end
end

function SWEP:ViewModelDrawn()
	local GM = gmod.GetGamemode()
	local itemclass = GM.invsel.curclass
	
	if itemclass then
		local item = GM.items[itemclass]
		if item then
			if item.onViewModelDrawn then
				local b,err = pcall(item.onViewModelDrawn,item,LocalPlayer()) //TODO: This will only draw for the local player, WILL CAUSE BUGS. Rename hook or fix.
				if not b then
					Error("\n",err)
				end
			end
		end
	end
end

hook.Add("HUDPaint","wsswep",SWEP.ViewModelDrawn) //ViewModelDrawn bug

function SWEP:ShouldDropOnDie()
	return false
end

function SWEP:PrimaryAttack()
	local GM = gmod.GetGamemode()
	
	local itemclass
	if SERVER then
		local uid = self.Owner:UniqueID()
		local inv = GM.pldat[uid].inventory
		itemclass = GM.pldat[uid].invsel
	elseif CLIENT then
		itemclass = GM.invsel.curclass
	end
	
	if itemclass then
		local item = GM.items[itemclass]
		if item then
			if item.onPrimary then
				local b,err = pcall(item.onPrimary,item,self.Owner)
				if not b then
					Error("\n",err)
				end
			end
		end
	end
end

function SWEP:SecondaryAttack()
	local GM = gmod.GetGamemode()
	
	local itemclass
	if SERVER then
		local uid = self.Owner:UniqueID()
		local inv = GM.pldat[uid].inventory
		itemclass = GM.pldat[uid].invsel
	elseif CLIENT then
		itemclass = GM.invsel.curclass
	end
	
	if itemclass then
		local item = GM.items[itemclass]
		if item then
			if item.onSecondary then
				local b,err = pcall(item.onSecondary,item,self.Owner)
				if not b then
					Error("\n",err)
				end
			end
		end
	end
end

function SWEP:GetViewModelPosition(pos,ang)
	ang:RotateAroundAxis(ang:Up(),180)
	return pos,ang
end













